package vn.vfriends.vcms.site.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import vn.vfriends.vcms.site.model.Category;
import vn.vfriends.vcms.site.model.Item;
import vn.vfriends.vcms.site.service.CategoryService;
import vn.vfriends.vcms.site.service.ItemService;

/**
 *
 * @author tuan@vfriends.vn
 */
@Named
@RequestScoped
public class ItemBean implements Serializable {
    
    @Inject private ItemService itemService;
    @Inject private CategoryService categoryService;
    
    private Long itemId;

    public Long getItemId() {
        return itemId;
    }

    public void setItemId(Long itemId) {
        this.itemId = itemId;
    }
    
    public Item getCurrentItem() {
        Item currentItem = null;
        if(itemId != null) {
            currentItem = this.itemService.findItem(itemId);
        }
        return currentItem;
    }
    
    public List<Category> getCategoryList() {
        Item currentItem = this.getCurrentItem();
        List<Category> categoryList = new ArrayList<Category>();
        if(currentItem != null) {
            categoryList = this.categoryService.findCategoriesByParent(currentItem.getCategory());
        }
        return categoryList;
    }
}
